﻿Public Class version

    Public vstring As String

    Private Function flag() As Boolean
        Dim f As String = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) & "\omnisource\flags\"
        FileIO.FileSystem.CurrentDirectory = f
        If FileIO.FileSystem.DirectoryExists(main.prjname) Then
            FileIO.FileSystem.CurrentDirectory = f & "\" & main.prjname
            FileIO.FileSystem.CreateDirectory(vstring)
            FileIO.FileSystem.CurrentDirectory = FileIO.FileSystem.CurrentDirectory & "\" & vstring
            FileIO.FileSystem.CopyDirectory(main.ProjectPath, FileIO.FileSystem.CurrentDirectory)
        Else
            FileIO.FileSystem.CreateDirectory(main.prjname)
            FileIO.FileSystem.CurrentDirectory = f & "\" & main.prjname
            FileIO.FileSystem.CreateDirectory(vstring)
            FileIO.FileSystem.CurrentDirectory = FileIO.FileSystem.CurrentDirectory & "\" & vstring
            FileIO.FileSystem.CopyDirectory(main.ProjectPath, FileIO.FileSystem.CurrentDirectory)
        End If
        Return True
    End Function

    Private Function getv(ByVal maj As Integer, ByVal min As Integer, ByVal bui As Integer, ByVal rev As Integer) As String
        Dim v As New System.Version(maj, min, bui, rev)
        Return v.ToString()
    End Function


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ok.Click
        Dim file As New IniFile
        file.RemoveAllSections()
        file.AddSection("version").AddKey("major").SetValue(major.Text)
        file.AddSection("version").AddKey("minor").SetValue(minor.Text)
        file.AddSection("version").AddKey("build").SetValue(build.Text)
        file.AddSection("version").AddKey("revision").SetValue(revision.Text)
        vstring = getv(Val(major.Text), Val(minor.Text), Val(build.Text), Val(revision.Text))
        file.Save(main.ProjectPath & "\omnisource.osp")
        Me.Close()
    End Sub

    Private Sub create_flag_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles create_flag.Click
        vstring = getv(Val(major.Text), Val(minor.Text), Val(build.Text), Val(revision.Text))
        If (flag()) Then
            Me.Enabled = True
        End If
    End Sub

    Private Sub cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cancel.Click
        Me.Close()
    End Sub
End Class